import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/showRequest")
public class ShowRequestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 使用 StringBuilder 把这些 api 结果拼接起来，统一写响应中
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(req.getProtocol());
        stringBuilder.append(req.getMethod());
        stringBuilder.append(req.getRequestURI());
        stringBuilder.append(req.getContextPath());
        stringBuilder.append(req.getQueryString());

        // 写回到响应中
        resp.getWriter().write(stringBuilder.toString());
    }
}
